<?php
namespace app\admin\common\controller;

use think\Controller;
use	think\Db;
use think\facade\Session;
use think\facade\Cookie;

class Common extends Controller
{
    public function _empty()
    {

    }
    public function initialize()
    {
        if(request()->action() != "index" && request()->action() != "insert" && request()->action() != "login" && request()->action() != "logout") {
            if(Session::get("userinfo.superior_id") != 0) {
                $this->redirect("index");
            }
        }
        if(Cookie::has("username")) {
            $user = Db::table("user")->where("username", Cookie::get("username"))->find();
            if($user["superior_id"] != 0) {
                $user["superiorname"] = Db::table("user")->where("id", $user["superior_id"])->value("username");
            }else {
                $user["superiorname"] = "BOSS";
            }
            unset($user["password"]);
            // unset($user["superior_id"]);
            Session::set("userinfo", $user);
        }else {
            if(!Session::has("userinfo")) {
                if(request()->action() != "login") {
                    $this->redirect("login");
                }
            }
        }
    }
}